package com.ungs.bo.impl;

import java.util.ArrayList;
import java.util.List;

import com.ungs.bo.StockMaterialBO;
import com.ungs.dao.StockMaterialDAO;
import com.ungs.dao.impl.StockMaterialDAOImpl;
import com.ungs.entities.OrdenTrabajo;
import com.ungs.entities.StockMaterial;
import com.ungs.filter.StockMaterialFilter;
import com.ungs.utils.Constantes;

public class StockMaterialBOImpl extends EntidadBOImpl<StockMaterial> implements
		StockMaterialBO {

	private StockMaterialDAO stockMaterialDAO = new StockMaterialDAOImpl();

	@Override
	public List<StockMaterial> getStockByFilter(
			StockMaterialFilter stockMaterialFilter) {
		return stockMaterialDAO.getStockByFilter(stockMaterialFilter);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<StockMaterial> getAllStockMaterial() {
		List<StockMaterial> stockMaterialList = (List<StockMaterial>) getAll(StockMaterial.class);
		List<StockMaterial> stockMaterialReturn = new ArrayList<StockMaterial>();

		logger.info("Obteniendo lista de stock material con alta logica");
		for (StockMaterial stockMaterial : stockMaterialList) {
			if (stockMaterial.getEstadoLogico().equals(Constantes.ALTA)) {
				stockMaterialReturn.add(stockMaterial);
			}
		}

		return stockMaterialReturn;
	}

	@Override
	public void eliminarStockMaterial(StockMaterial stockMaterial) {
		logger.info("Baja logica stockMaterial: " + stockMaterial.getId());
		stockMaterial.setEstadoLogico(Constantes.BAJA);
		actualizar(stockMaterial);

	}

	@Override
	public StockMaterial getStockMaterial(StockMaterial stockMaterial) {
		return stockMaterialDAO.getStockMaterial(stockMaterial);
	}

	@Override
	public List<StockMaterial> getStockByOrdenTrabajo(OrdenTrabajo ordenTrabajo) {
		return stockMaterialDAO.getStockByOrdenTrabajo(ordenTrabajo);
	}

}
